import { configureStore } from '@reduxjs/toolkit'
import { TypedUseSelectorHook , useSelector, useDispatch, shallowEqual} from 'react-redux'
import counterReducer from './modules/counter'
import recommendReducer from '@/views/discover/c-views/recommend/store/recommend'

const store = configureStore({
  reducer: {
    counter: counterReducer,
    recommend: recommendReducer,
  }
})

// typeof store.getState => 函数类型
// ReturnType<函数类型> => 函数类型的返回类型
type RootState = ReturnType<typeof store.getState>

// 推断出类型: {posts: PostsState, comments: CommentsState, users: UsersState}
type AppDispatch = typeof store.dispatch

// 在整个应用程序中使用，而不是简单的 `useDispatch` 和 `useSelector`
export const useAppDispatch: () => AppDispatch = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector 
export const shallowEqualApp = shallowEqual


export { type RootState, type AppDispatch}

export default store